#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：3.协程并发.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-07 09:55
'''
import asyncio
import time


async def work1():
    for i in range(5):
        print(f"这是任务1开始：{i}")
        await asyncio.sleep(1)
        print(f"这是任务1结束：{i}")

async def work2():
    for i in range(5):
        print(f"这是任务2开始：{i}")
        await asyncio.sleep(1)
        print(f"这是任务2结束：{i}")

async  def main():
    # 构建了一个任务列表
    task = [asyncio.create_task(work1()), asyncio.create_task(work2())]
    await asyncio.wait(task)
#
# start_time = time.time()
# asyncio.run(main())
# end_time = time.time()
#
# print(f"耗时：{end_time - start_time}")

work1()